import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
import { BaHttp } from '../../../theme/baHttp/baHttp.service';
@Component({
  selector: 'add-business',
  templateUrl: 'addbusiness.html'
})
export class Addbusiness {
  public f_SourceId:string;
  public f_Amount:string;
  public f_EnCode:string;
  public f_ChanceTypeId:string;
  public f_FullName:string;
  public f_Profit:string;
  public f_StageId:string;
  public f_Tel:string;
  public f_QQ:string;
   tabBarElement: any;
  constructor(
      public navCtrl: NavController,
      public alertCtrl: AlertController,
      private _http: BaHttp
  ) {
    if (document.querySelector('.tabbar')) {
      this.tabBarElement = document.querySelector('.tabbar.show-tabbar');
    }
  }
  ionViewWillEnter() {
    if (this.tabBarElement) {
      this.tabBarElement.style.display = 'none';
    }
  }

  ionViewWillLeave() {
    if (this.tabBarElement) {
      this.tabBarElement.style.display = 'flex';
    }
  }
  public AddBusiness(): void {
      let postData = {
          'F_EnCode': this.f_EnCode,
          'F_FullName': this.f_FullName,
          'F_SourceId': this.f_SourceId,
          'F_StageId': this.f_StageId,
          'F_SuccessRate': '',
          'F_Amount': this.f_Amount,
          'F_Profit': this.f_Profit,
          'F_ChanceTypeId': this.f_ChanceTypeId,
          'F_SaleCost': '',
          'F_QQ': this.f_QQ,
          'F_Tel': this.f_Tel
      };
      if (this.f_SourceId === null || this.f_SourceId === undefined || this.f_SourceId === "") {
          let alert = this.alertCtrl.create({
              title: '提示信息',
              subTitle: '商机名称不能为空',
              buttons: ['确认']
          });
          alert.present();
      } else if (this.f_Amount === null || this.f_Amount === undefined || this.f_Amount === "") {
          let alert = this.alertCtrl.create({
              title: '提示信息',
              subTitle: '预计金额不能为空',
              buttons: ['确认']
          });
          alert.present();
      } else if (this.f_EnCode === null || this.f_EnCode === undefined || this.f_EnCode === "") {
          let alert = this.alertCtrl.create({
              title: '提示信息',
              subTitle: '商机来源不能为空',
              buttons: ['确认']
          });
          alert.present();
      } else if (this.f_ChanceTypeId === null || this.f_ChanceTypeId === undefined || this.f_ChanceTypeId === "") {
          let alert = this.alertCtrl.create({
              title: '提示信息',
              subTitle: '商机阶段不能为空',
              buttons: ['确认']
          });
          alert.present();

      } else if (this.f_FullName === null || this.f_FullName === undefined || this.f_FullName === "") {
          let alert = this.alertCtrl.create({
              title: '提示信息',
              subTitle: '公司名称不能为空',
              buttons: ['确认']
          });
          alert.present();
      } else if (this.f_Profit === null || this.f_Profit === undefined || this.f_Profit === "") {
          let alert = this.alertCtrl.create({
              title: '提示信息',
              subTitle: '跟进人员不能为空',
              buttons: ['确认']
          });
          alert.present();
      } else if (this.f_StageId === null || this.f_StageId === undefined || this.f_StageId === "") {
          let alert = this.alertCtrl.create({
              title: '提示信息',
              subTitle: '联系人不能为空',
              buttons: ['确认']
          });
          alert.present();
      }
      else {
          this._http.post('http://localhost:31173/business/send', postData, (res) => {
              let alert = this.alertCtrl.create({
                  title: '提示信息',
                  subTitle: '商机信息添加成功！',
                  buttons: ['确认']
              });
              alert.present();
          })
      }
  }
}
